<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 二维数组转置
        var arr = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l']];
        var res = [[], [], []];
        // console.log(arr.length);//4
        // console.log(arr[0].length);//3
        // console.log(res.length);//3
        // console.log(res[0].length);//0
        for (let i = 0; i < arr[0].length; i++) {
            for (let j = 0; j < arr.length; j++) {
                res[i][j] = arr[j][i];
                // document.write(res[i][j] + ' ');
            }
            // document.write('<br>');
        }
        console.log(res);


        // 采用冒泡排序，从大到小排序，数组是 70,35,67,49,20,59,98,100
        var arr = [70, 35, 67, 49, 20, 59, 98, 100];
        for (var i = 0; i < arr.length - 1; i++) {
            for (var j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] < arr[j + 1]) {
                    var temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        console.log(arr);


        // 输出任意一个二维数组中数据的个数
        var arr1 = [[1, 3], [2, 4]];
        var arr2 = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l']];
        var arr3 = [['a', 'b', 'c'], ['d', 'e', 'f'], [70, 35, 67, 49, 20, 59, 98, 100]];
        var num = prompt('请输入想要查询那个二维数组的数据个数\n' + 'arr1,   arr2,   arr3');
        // console.log(num);
        var sum = 0;
        if (num == 'arr1') {
            for (var i = 0; i < arr1.length; i++) {
                for (var j = 0; j < arr1[i].length; j++) {
                    sum++;
                }
            }
        }
        if (num == 'arr2') {
            for (var i = 0; i < arr2.length; i++) {
                for (var j = 0; j < arr2[i].length; j++) {
                    sum++;
                }
            }
        }
        if (num == 'arr3') {
            for (var i = 0; i < arr3.length; i++) {
                for (var j = 0; j < arr3[i].length; j++) {
                    sum++;
                }
            }
        }
        console.log(num + '的数据个数为：' + sum);


        // 数组去重
        var arr = [70, 35, 67, 50, 49, 20, 59, 70, 50, 98, 100];
        var newArr = [];
        // for (var i = 0; i < arr.length; i++) {
        //     if (newArr.indexOf(arr[i]) == -1) {
        //         newArr.push(arr[i]);
        //     }
        // }
        // console.log(newArr);

        for (var i = 0; i < arr.length; i++) {
            for (var j = i + 1; j < arr.length; j++) {
                if (arr[i] == arr[j]) {
                    delete arr[j];
                }
            }
        }
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                newArr[newArr.length] = arr[i];
            }
        }
        console.log(newArr);
    </script>
</body>

</html>